<template>
  <div class="mod-config">
    <basic-container>
      <div class="boxsty zhiBiao" v-if="zhiShow==1">
      <div class="avue-crud">
        <div  style="border-top: 1px solid #b0bde2">
          <div class="mt10" style="padding-bottom: 20px">
            <div style="float:right">
                 <el-button type="primary" @click="plsh()">批量审核</el-button>
              </div>
          </div>
        </div>
        <el-table
         ref="table"
          style="width: 100%;margin-top:20px"
          :data="dataList"
          border
          v-loading="dataListLoading">
          <el-table-column type="selection" width="55" header-align="center" align="center"></el-table-column>
        <el-table-column type="index" width="80" header-align="center" align="center" label="序号"></el-table-column>
          <el-table-column
            prop="contractName"
            header-align="center"
            align="center"
            width="160"
            label="合同名称">
            <template slot-scope="scope">
              <span  v-if="permissions.hetongrenwu_hetonghtxxdjb_edit" @click="checkDetails(scope.row)" style="color:#0e258c;cursor: pointer;">{{scope.row.contractName}}</span>
              <span v-else>{{scope.row.contractName}}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="shouyueName"
              header-align="center"
              align="center"
              min-width="120"
              label="受约人姓名">
              <template slot-scope="scope">
              <div v-for="(item,index) in cutout(scope.row.shouyueName).slice(0, 2)">
                  <el-tooltip class="item" :disabled="cutout(scope.row.shouyueName).length<3" effect="dark" :content="scope.row.shouyueName" placement="top-start">
                  <span>{{item}}<span v-if="cutout(scope.row.shouyueName).length>2&&index==1">...</span></span>
                  </el-tooltip>
              </div>
              </template>
          </el-table-column>

          <el-table-column
            prop="contractAuditStatus"
            header-align="center"
            align="center"
            label="节点">
            <template slot-scope="scope">
              <span v-html="cutout2(scope.row.contractAuditStatus)"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="textreviewDatetime"
            header-align="center"
            align="center"
            show-overflow-tooltip
            label="接收时间">
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            fixed="right"
            label="操作">
            <template slot-scope="scope">
              <el-button v-if="permissions.hetongrenwu_hetonghtxxdjb_edit"  type="primary" @click="tracking(scope.row)" plain size="small">合同跟踪#
              </el-button>
            </template>
          </el-table-column>
        </el-table>
          <div class="avue-crud__pagination">
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
                            :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background
                            layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
            </div>
      </div>
      </div>
        <zhibiaoForm ref="zhibiaoRef" v-if="zhiShow==2" :zhibiaoForm='zhibiaoForm'  v-on:zhibiaoChild='zhibiaoChild' :hetongId="hetongId"  :htqdorwbsh="htqdorwbsh" ></zhibiaoForm>
       <genzongForm v-if="genzongFormData.dialogVisible"  :genzongFormData='genzongFormData' ></genzongForm>

    </basic-container>
  </div>
</template>

<script>
import {fetchList, delObj,radioTwoList} from '@/api/hetongrenwu/hetonghtxxdjb'
import {gethtlist} from '@/api/hetongrenwu/hetongyeji/hetongnd'
import {mapGetters} from 'vuex'
import { page } from '@/api/hetongrenwu/hetongyeji/hetongnd'
import zhibiaoForm from '@/views/hetongrenwu/components/zhibiao-form.vue'
import genzongForm from '@/views/hetongrenwu/components/genzong-form.vue'
import {updateplshByid} from '@/api/hetongrenwu/hetongyeji/hetongnd'
import { validatenull } from "@/util/validate";
export default {
  components:{
        zhibiaoForm,
        genzongForm

    },
  data() {
    return {
      streamId: Number,
      htId: Number,
      programInterface: '',
      streamType: '',
      dataForm: {
        key: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      radio:'1',
      radioTwo:'1',
      zhiShow:1,
      zhibiaoForm:{},
      genzongFormData:{},
      searchadvanced: true,
      searchheight: '0',
      htdataList:{},
      treeOrgData:[],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      iswenben:1,
      selectedTreeData:[],
      fdata:{},
      contractAuditStatus:2,
      zbvisible:false,
      hetongId:Number,
      rowid:Number,
      htqdorwbsh:'',
      radioTwoList:radioTwoList
    }
  },

  watch:{
    radio(value){
      if(value){
       // this.getDataList();
      }
    }
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    init(formInfo,
        formInfoDetailed,
        formData,
        GUID,
        wfYwMain,
        wfYwStream,
        dqYwStream,
        dqTask){
          this.dataForm.id = wfYwMain.ywLyid
          this.streamId = dqYwStream.id
          this.programInterface = dqTask.programInterface
          this.getDataList()
    },
    getFormData() {
        this.$emit("returnFormData", null);
    },
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if(this.searchadvanced){
        this.searchheight= 'auto'
      }
    },

    //合同跟踪
    tracking(row){
        this.rowid=row.id;
       //console.log(this.rowid)
        this.genzongFormData={
          dialogVisible:true,
               rowid:row.id
             }
         //console.log(this.rowid)
    },
    //查看
    checkDetails(row){
        this.htqdorwbsh='wbsh';
        this.hetongId=row.id;
        this.zhiShow=2;
        this.zhibiaoForm={
            enter:2,
            disabled:true,
            hetongId:row.id,
            streamId:this.streamId
        }
        gethtlist(row.id).then(response => {
          this.htdataList = response.data
          this.$nextTick(()=>{
            this.$refs.zhibiaoRef.getDataList();
            this.$refs.zhibiaoRef.saveForm(this.htdataList.data)
        })
      })

    },
    plsh(){
      var data=this.$refs.table.selection;
      if(data.length==0){
        this.$message.error("请至少选择一个合同！");
        return;
      }
      var ids=[];
      for(var i=0;i<data.length;i++){
        ids.push(data[i].id)
      }
      var idsStr=ids.join(',')
      this.$confirm('是否要批量审核吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return updateplshByid({ids:idsStr,contractAuditStatus:4})
      }).then(data => {
        this.$message.success('文本审核成功');
        this.$emit("refreshTableData");
        this.getDataList()
      })
    },
    //子集信息
        zhibiaoChild(zhibiaoChild){
            if(zhibiaoChild){
                this.zhiShow=1;
                this.getDataList()
            }
        },
    // 获取数据列表
     getDataList() {
      this.dataListLoading = true
      page(Object.assign({ current: this.pageIndex,
                size: this.pageSize},this.dataForm)).then(response => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total
      })
      this.dataListLoading = false
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle(id) {
      this.$confirm('是否确认删除ID为' + id, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getDataList()
      })
    },
    cutout(cellValue) {
      if (cellValue) {
        var c = cellValue.split(",");
        if(c.size<1){
          c.push('-');
          c.push('-');
        } else if(c.size<2){
          c.push('-');
        }
        return c;
      }
    },
    cutout2(cellValue) {
     if(cellValue==0){
       return '创建中';
     }
      if(cellValue==1){
        return '审核中';
      }
      if(cellValue==2){
        return '审核退回';
      }
      if(cellValue==3){
        return '审核完成';
      }
      if(cellValue==4){
        return '签订中';
      }
      if(cellValue==5){
        return '已退回';
      }
      if(cellValue==5){
        return '审核通过';
      }
    }
  }
}
</script>
